/*
 * UIModel.java
 * 
 * Created on Aug 18, 2007, 8:44:57 PM
 * 
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package org.usixml.model;

import java.util.UUID;

/**
 *
 * @author htmfilho
 */
public class UIModel implements Model {
    private String id = null;
    
    public String getId() {
        if(this.id == null)
            this.id = createId();
        return this.id;
    }

    public void setId(String id) {
        this.id = id;
    }
    
    public boolean equals(Object object) {
        if (this == object) return true;
        if (object == null || !(object instanceof Model)) return false;

        Model other = (Model)object;

        if (id == null) return false;

        return id.equals(other.getId());
    }
    
    public int hashCode() {
        if (id != null)
            return id.hashCode();
        else
            return super.hashCode();
    }
    
    private static String createId() {
        UUID uuid = UUID.randomUUID();
        return uuid.toString().replaceAll("-", "");
    }
}
